﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CADDemo2025
{
    public class Command0204
    {
        private Dictionary<string, object> originalValues = new Dictionary<string, object>();
        [CommandMethod("Demo02041")]
        public void Demo02041()
        {
            if (!UmUserMethod.GetEntity(out Entity entity)) return;
            originalValues.Clear();
            var properties = entity.GetType().GetProperties();
            foreach (var prop in properties)
            {
                if (prop.CanWrite == false) continue;
                originalValues[prop.Name] = prop.GetValue(entity);
            }
        }
        [CommandMethod("Demo02042")]
        public void Demo02042()
        {
            if (!UmUserMethod.GetEntity(out Entity entity)) return;
            WCAD.Ed.WriteMessage("\n");
            var properties = entity.GetType().GetProperties();
            foreach (var prop in properties)
            {
                if (prop.CanWrite == false) continue;
                var currentValue = prop.GetValue(entity);
                if (!originalValues.ContainsKey(prop.Name))
                    continue;
                var originalValue = originalValues[prop.Name];
                if (!Equals(currentValue, originalValue))
                {
                    WCAD.Ed.WriteMessage($"'{prop.Name}'：'{originalValue}'   '{currentValue}'\n");
                }
            }
        }
    }
}
